var mongoose = require('mongoose'),
  UserModel = require('../models/Models/User'),
  StationModel = require('../models/Models/Station'),
  LabelModel = require('../models/Models/Label'),
  ConfigModel = require('../models/Models/Config'),
    StationHistoryModel = require('../models/Models/StationHistory'),
    LabelHistoryModel = require('../models/Models/LabelHistory'),
    AreaModel = require('../models/Models/Area');
mongoose.Promise = require('bluebird');

module.exports = function (config) {
  mongoose.connect(config.db, {
    useMongoClient: true
  });

  var db = mongoose.connection;
  db.once('open', function (err) {
    if (err) {
      console.log('Database could not be opened: ' + err);
      return;
    }
    console.log('Database up and running...')
  });

  db.on('error', function (err) {
    console.log('Database error: ' + err);
  });

  UserModel.init();
  StationModel.init();
  LabelModel.init();
  ConfigModel.init();
  StationHistoryModel.init();
  LabelHistoryModel.init();
  AreaModel.init();
}